package com.yoga.manager.qrcodeUtil;

import com.yoga.manager.upyun.UploadChannelEnum;
import org.apache.commons.lang.StringUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Created by chenjin on 2020/9/19.
 */
public class TbQrCodeUtil {

    private final static String androidUrl = "https://s.m.taobao.com/h5?"; //h5

    private final static String iphpneUrl = "https://s.m.taobao.com/seach?";

    private final static String totalUrl="https://s.taobao.com/search?";

    /**
     *
     * 通用*/
    public static String getTotalUrl(String keyword, String itemId) throws UnsupportedEncodingException {

        keyword = keyword.trim().replace(" ", "");
        String keyw = URLEncoder.encode(keyword, "UTF-8");
        if (StringUtils.isEmpty(itemId)) {
            return null;
        }
        String url = totalUrl + "q=" + keyw + "&showtype=similar&graphnid=" + itemId;
        QRConfig qrConfig = new QRConfig();
        qrConfig = new QRConfig();
        qrConfig.setImageFormat("png");
        qrConfig.setWidth(120);
        qrConfig.setHeight(120);
        return UploadQrcodeUtil.doing(url, UploadChannelEnum.YOGA_IMG,qrConfig);
    }



    public static String getAndroidUrl(String keyword, String itemId) throws UnsupportedEncodingException {

        keyword = keyword.trim().replace(" ", "");
        String keyw = URLEncoder.encode(keyword, "UTF-8");
        if (StringUtils.isEmpty(itemId)) {
            return null;
        }
        String url = androidUrl + "q=" + keyw + "&closeP4P=true&nid_up=" + itemId + "&scm=1007.13113.64422.tab:3_type";
        QRConfig qrConfig = new QRConfig();
        qrConfig = new QRConfig();
        qrConfig.setImageFormat("png");
        qrConfig.setWidth(120);
        qrConfig.setHeight(120);
        return UploadQrcodeUtil.doing(url, UploadChannelEnum.YOGA_IMG,qrConfig);
    }

    public static String getIphpneUrl(String keyword, String itemId) throws UnsupportedEncodingException {

        keyword = keyword.trim().replace(" ", "");
        String keyw = URLEncoder.encode(keyword, "UTF-8");
        if (StringUtils.isEmpty(itemId)) {
            return null;
        }
        String url = iphpneUrl + "q=" + keyw + "&OpenP4P=true&nid_up=" + itemId + "&&qq-pf-to=pcqq.c2c";
        QRConfig qrConfig = new QRConfig();
        qrConfig = new QRConfig();
        qrConfig.setImageFormat("png");
        qrConfig.setWidth(120);
        qrConfig.setHeight(120);
        return UploadQrcodeUtil.doing(url, UploadChannelEnum.YOGA_IMG,qrConfig);
    }

}
